package com.example.hyw.szysteam.presenter;

import android.support.v7.app.AppCompatActivity;
import android.util.Log;

import com.example.hyw.szysteam.POJO.ClassItem;
import com.example.hyw.szysteam.POJO.HttpResult;
import com.example.hyw.szysteam.model.ClassModel;
import com.example.hyw.szysteam.view.ClassActivity;

import java.util.ArrayList;
import java.util.List;

import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.functions.Consumer;
import io.reactivex.schedulers.Schedulers;

/**
 * Created by HYW on 2018/6/8.
 */

public class GetClassPresenter {
    ClassModel classModel=new ClassModel();
    ClassActivity classActivity;

    public GetClassPresenter(ClassActivity classActivity) {
        this.classActivity = classActivity;
    }

    public void getClass(String email){
        classModel.getclass(email)
                .subscribeOn(Schedulers.io())
                .unsubscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Consumer<HttpResult<ArrayList<ClassItem>>>() {
                    @Override
                    public void accept(HttpResult<ArrayList<ClassItem>> arrayListHttpResult) throws Exception {
                        ArrayList<ClassItem> classItems=arrayListHttpResult.getContent();
                        if(classItems!=null){
                            classActivity.initListView(classItems);
                        }else {
                            classActivity.noClass();
                        }
                    }
                });
    }
}
